<extend name="Public/content" />
<block name="style">
<style type="text/css">
    .table>tbody>tr>td{ padding: 4px; vertical-align: middle;}
        body{ background: #fff;}

  .footer {
    width: 100%;
    height: 50px;
    position: fixed;
    bottom: 0;
   
    left: 0;
    line-height: 50px;
    text-align: right;
    text-align: right;
    border-top: solid 1px #eee;
    padding-right: 10px;
    z-index: 999999999999999;
}
</style>
</block>
<block name="body">
    <form action="{:U('Nav/save_power')}" method="post" id="searchForm">
        <input type="hidden" name="id" value="{$id}" id="id">
        <input type="hidden" name="rules" id="rules" value="" > 
    <include file="Public:artdialog" />
    <div class="row">
        <div class="col-md-12">
            <div class="block-web">


                <div class="porlets-content">
                                <td style="padding-left: 50px;">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">权限分配：</label>
                                        <div class="col-sm-9">
                                            <div style="width: 100%;">
                                                <a href="javascript:;" onclick="checkAllTrue()" class="btn btn-success btn-xs">全选</a>&nbsp;
                                                <a href="javascript:;" onclick="checkAllFalse()" class="btn btn-success btn-xs">取消</a>&nbsp;
                                                <a href="javascript:;" onclick="expandAll()" class="btn btn-success btn-xs">展开</a>&nbsp;
                                                <a href="javascript:;" onclick="collapseAll()" class="btn btn-success btn-xs">折叠</a>&nbsp;
                                            </div>
                                            <div style="width: 100%;">
                                                <ul id="treeRule" class="ztree"></ul>
                                            </div>
                                        </div>
                                    </div>
                                </td>

                </div><!--/porlets-content-->
            </div><!--/block-web-->
        </div><!--/col-md-12-->
    </div>

   <div class="footer" >
    <button class="btn btn-primary btn-success bt_submit" id="submit" type="button" onclick="sub_quanxian()">提交</button>
    <button class="btn btn-default bt_close" type="button" onclick="art.dialog.open.api.close();" >关闭</button>
</div>  
</form>
</block>

<block name="script">
 <include file="Public:tree" />
<script type="text/javascript">
  _hide_public_loading();
var id = "{$id}";

     var setting = {
            view: {
                selectedMulti: false
            },
            check: {
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };
        var treeObj;
        function createTree() {
            $.post("{:U('Nav/menu_ajax',array('id'=>$id))}",function(resultobj){
                treeObj= $.fn.zTree.init($("#treeRule"), setting, resultobj);
               
            });



        }

        $(function(){
            createTree();
        });
        function checkAllTrue(){
            treeObj.checkAllNodes(true);
        }
        function checkAllFalse(){
            treeObj.checkAllNodes(false);
        }
        function expandAll(){
            treeObj.expandAll(true);
        }
        function collapseAll(){
            treeObj.expandAll(false);
        }
    // $(function(){
    //     goSearch("#searchForm","order_list_item_content");
    // });

function  sub_quanxian(){
             huoquanxian();

            showvfmsg("-1", '提交中，请稍后...', 999999); 
             var url="{:U('Nav/save_power')}";
                $.ajax({
                    'url':url,
                    'data':$('#searchForm').serialize(),
                    'dataType':'json',
                    'type':'post',
                    beforeSend:function(){
                         $("#submit").attr("disabled",'disabled');
                         $("#submit").html("提交中...");
                         $(".bt_submit").attr("disabled", 'disabled');
                         $(".bt_submit").html("提交中...");
                    },
                    success:function(data){
                            $("#submit").removeAttr('disabled');
                            $("#submit").html("提交");
                            $(".bt_submit").removeAttr('disabled');
                            $(".bt_submit").html("提交");
                            var retstatus = data.state == 1 ? "1" : "0";
                            showvfmsg(retstatus, data.msg, 1900);
                            if(retstatus ==1){
                               setTimeout(function(){art.dialog.open.api.close();},1000)

                            }
                        // goSearch("#searchForm","order_list_item_content");

                        //_reload_currentpage_datalist('order_list_item_content');
                        // goSearch("#searchForm","order_list_item_content");


                    },error:function(){
                        showvfmsg('error','请求服务器失败',2000);
                    },complete:function(){
                            $("#submit").removeAttr('disabled');
                            $("#submit").html("提交");
                            $(".bt_submit").removeAttr( 'disabled');
                            $(".bt_submit").html("提交");
                    }
      })
       
}

function huoquanxian(){
        var nodes=treeObj.getCheckedNodes(true);
        var newArrays=new Array();
        for(var  i=0;i<nodes.length;i++){
            newArrays.push(nodes[i].id);
        }
        // console.info(newArrays);
        $("#rules").val(newArrays.join(","));
    }


    function load(){
        goSearch("#searchForm","order_list_item_content");
    }

    function toParentChilder(id){
        $('#parent_id').val(id);
        goSearch("#searchForm","order_list_item_content");
    }


    function delete_ok(id){
        art.dialog({
            content: "是否确认删除，如果是会自动删除关联数据",
            icon: 'question',
            lock: true,
            opacity: 0.2,
            id:'dele',
            ok: function () {
                var url="{:U('Nav/delete_ok')}";
                $.ajax({
                    'url':url,
                    'data':{id:id},
                    'dataType':'json',
                    'type':'post',
                    success:function(data){

                        goSearch("#searchForm","order_list_item_content");

                        //_reload_currentpage_datalist('order_list_item_content');
                        // goSearch("#searchForm","order_list_item_content");
                        var retstatus = data.status == 1 ? "1" : "0";
                        showvfmsg(retstatus, data.info, 1900);

                    },error:function(){
                        showvfmsg('error','请求服务器失败',2000);
                    },complete:function(){

                    }
                });


            },
            cancelVal: '取消',
            cancel: true
        });
    }

    function return_up(){
        var url="{:U('Auth/return_up')}";
        $.post(url,{"parent_id":$("#parent_id").val()},function(resultObj){
               if(resultObj.status==1){
                   $("#parent_id").val(resultObj.info);
                   goSearch("#searchForm","order_list_item_content");
               }else{
                   showvfmsg('error',resultObj.info,2000);
               }
        });
    }

    function return_main(){
        $("#parent_id").val(0);
        goSearch("#searchForm","order_list_item_content");
    }



       

</script>
</block>